﻿using System;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using UDS.Components;
using UDS.Entity;

namespace UDS.SubModule.UnitiveDocument.DocumentFlowPages
{
    /// <summary>
    /// DisplayStyle 的摘要说明。
    /// </summary>
    public partial class DisplayStylePage : Page
    {
        private int _styleId;

        protected FlowStyle CurrentFlowStyle
        {
            get;
            private set;
        }

        protected override void OnLoad(EventArgs e)
        {
            _styleId = QSUtil.GetPositiveInt32("StyleID");
            CurrentFlowStyle = FlowStyle.GetFlowStyle(_styleId);

            repeater.DataSource = FlowStyleDescription.GetStyleDescription(_styleId);
            repeater.DataBind();

            base.OnLoad(e);
        }

#if false
        private void Bangding()
        {
            var tt = styleTable;

            // AddRow(tt, "表单示例", "../../../Images/treetopbg.jpg");
            IList<FlowStyleDescription> list = FlowStyleDescription.GetStyleDescription(_styleId);
            foreach (FlowStyleDescription field in list)
            {
                var txt = new TextBox();

                txt.ID = "txt" + field.Name;
                if (field.Multiline)
                {
                    txt.TextMode = TextBoxMode.MultiLine;
                }
                txt.Height = field.Height;
                txt.Width = field.Width;
                txt.CssClass = "Input3";

                var tr = new TableRow();
                var tl = new TableCell();
                var tc = new TableCell();
                var ta = new TableCell();

                var lt = new Literal();

                ta.VerticalAlign = VerticalAlign.Top;
                ta.Width = Unit.Percentage(5);
                lt.Text = field.Example;

                tc.Controls.Add(txt);
                tc.Controls.Add(lt);
                tc.Width = Unit.Percentage(80);

                tl.Text = field.Description + ":";
                tl.Width = Unit.Percentage(15);

                if (field.Multiline)
                {
                    tl.VerticalAlign = VerticalAlign.Top;
                }
                else
                {
                    tl.VerticalAlign = VerticalAlign.Middle;
                }
                tl.HorizontalAlign = HorizontalAlign.Right;

                tr.Cells.Add(ta);
                tr.Cells.Add(tl);
                tr.Cells.Add(tc);
                tt.Rows.Add(tr);
            }

            AddAttachControl(tt);
            AddRow(tt, "<a href='#' onclick='history.back();'>返回</a>", "");

            // frmDisplayStyle.Controls.Add(tt);
        }

        private void AddAttachControl(Table tab)
        {
            string Template = FlowStyle.GetStyleTemplate(_styleId);
            if (!string.IsNullOrEmpty(Template))
            {
                var tr = new TableRow();
                var td = new TableCell();
                var tl = new TableCell();
                var tt = new TableCell();

                tt.Text = " ";
                tr.Cells.Add(tt);

                td.Text = "<a href='" + Template + "' style='text-decoration: underline' titile='模板下载'>模板</a>:";
                td.HorizontalAlign = HorizontalAlign.Right;
                tr.Cells.Add(td);

                var hif = new HtmlInputFile();
                hif.ID = "fileTemplate";
                hif.Name = "fileTemplate";
                hif.Style["width"] = "450px";
                hif.Style["Class"] = "Input3";

                tl.Controls.Add(hif);
                tr.Cells.Add(tl);

                tab.Rows.Add(tr);
            }
        }

        private void AddRow(Table tab, string Caption, string BackGround)
        {
            var tr = new TableRow();
            var td = new TableCell();

            td.Text = Caption;
            td.ColumnSpan = 3;
            td.Height = 28;

            tr.Cells.Add(td);

            tr.HorizontalAlign = HorizontalAlign.Center;
            td.Attributes["background"] = BackGround;
            tab.Rows.Add(tr);
        }
#endif
    }
}